<?php
/*
 * Created on Apr 4, 2006
 *
 */
 	require_once('config.php');
 	require_once('functions/general.php');
	require_once('functions/sql.php');
	require_once('sql/sql_offense.php');
	require_once('sql/sql_offender.php');
	require_once('Smarty.class.php');
	
	session_start();
	
	$smarty = new Smarty;
	$smarty->assign('CONFIG', $CONFIG);
	$mysql_link = get_mysql_link();
	logged_in_status($smarty);
	$offender = new Sql_offender();
	
	if ($_GET[type] == "description" and $_GET[offender]) {
		//display description form
		if (!$offender->exists($_GET[offender]))
			die ("Offender does not exist.");
		
		$smarty->assign('description',$offender->get_description($_GET[offender]));
		$smarty->assign('offender', $_GET[offender]);
		$smarty->display('edit_description.tpl');
	}
	
	else if ($_GET[type] == "action" and $_GET[offender]) {
		//display action form
		if (!$offender->exists($_GET[offender]))
			die ("Offender does not exist.");
		
		$smarty->assign('offender', $_GET[offender]);
		$smarty->display('edit_action.tpl');
		
	}
	
	else if ($_POST[type] == "description" and $_POST[description] and $_POST[offender]) {

		//insert a new description to database
		if (!$offender->exists($_POST[offender]))
			die ("Offender does not exist.");
		
		$offender->insert_description($_POST[offender], $_POST[description]);
		
		$smarty->assign('title', "Beskrivelse lagt til");
		$smarty->assign('message', "<strong>Suksess!</strong><br /><br />Beskrivelsen er lagt til. Tilbake til
					 <a href=\"browse.php?category=offender&amp;selection=$_POST[offender]\">
					 $_POST[offender]</a>?");
		$smarty->display('success.tpl');
		
	}
	
	else if ($_POST[type] == "action" and $_POST[action] and $_POST[offender]) {
		//insert a new action to database
		if (!$offender->exists($_POST[offender]))
			die ("Offender does not exist.");
		
		$offender->insert_action($_POST[offender], $_POST[action]);
		$smarty->assign('title', "Tiltak lagt til");
		$smarty->assign('message', "<strong>Suksess!</strong><br /><br />Tiltaket er lagt til. Tilbake til
					 <a href=\"browse.php?category=offender&amp;selection=$_POST[offender]\">
					 $_POST[offender]</a>?");
		$smarty->display('success.tpl');
	
	}
	
	
	else {
		$smarty->assign('title', "Ingenting å redigere");
		$smarty->assign('message', "Intenting å legge til/redigere.");
		$smarty->display('warning.tpl');
	
	}
	mysql_close($mysql_link);
	
?>
